using System;

using Oracle.DataAccess.Client;
using System.Data;

namespace IP.Core.IPBusinessService
{
	/// <summary>
	/// Summary description for OracleParameterConvert.
	/// </summary>
	public class OracleParameterConvert {
		public OracleParameterConvert() {
			//
			// TODO: Add constructor logic here
			//
		}

		public static string get_string_value_for_DML(OracleParameter i_ora_param) {
			if (i_ora_param.Value == DBNull.Value) {
				return " null ";
			}

			if( i_ora_param.OracleDbType == OracleDbType.Varchar2) {
				string v_str_varchar = i_ora_param.Value.ToString() 	;
				v_str_varchar = v_str_varchar.Replace("'","''");

				return "'" + v_str_varchar+  "'";
			}
			else if ( i_ora_param.OracleDbType == OracleDbType.Date) {
				
					return " to_date(" + Date2Str_VNFormat((DateTime)i_ora_param.Value) + "," + GetDateFormatString() + ") ";
			
			} else if ( i_ora_param.OracleDbType == OracleDbType.Decimal) {
					string v_str_dec = ((Decimal)(i_ora_param.Value)).ToString().Replace(",",".");
					return v_str_dec;
			}
			return null;
				
		}

		private static string GetDateFormatString() {
			return "'dd/mm/yyyy'";
		}
		private static string Date2Str_VNFormat(DateTime i_date) {
			string v_str =  "'" +i_date.Day.ToString() + "/" + i_date.Month.ToString()+ "/"+i_date.Year.ToString() + "'";
			return v_str;

		}
	}
}
